package com.wanghlme.day29.homework.web;

import com.alibaba.fastjson.JSONObject;
import com.wanghlme.day29.homework.data.Series;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getData")
public class GetDataAction extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("titleText", "手机销量");
        List<Series> dataList = new ArrayList<>();
        dataList.add(new Series("Huawei", "987"));
        dataList.add(new Series("Apple", "876"));
        dataList.add(new Series("Xiaomi", "765"));
        dataList.add(new Series("OPPO", "654"));
        dataList.add(new Series("VIVO", "543"));
        dataList.add(new Series("MEIZU", "432"));
        PrintWriter out = resp.getWriter();
        out.print(JSONObject.toJSONString(dataList));
        out.flush();
        out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
